package work823;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class work6Server {
  public static void main(String[] args) {
    ServerSocket serverSocket = null;
    try {
      try {
        serverSocket = new ServerSocket(8888);
        System.out.println("服务器已启动，等待客户端连接请求");
        Socket socket = serverSocket.accept();
        InputStream is = socket.getInputStream();
        DataInputStream dis = new DataInputStream(is);
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String fileName = br.readLine();
        System.out.println(fileName);
        File file = new File("E:\\bdqn\\javaDemo\\3\\"+fileName.substring(0,fileName.length()-4));
        DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
        int len = -1;
        while ((len = dis.read())!= -1){
          dos.write(len);
          dos.flush();
        }
        socket.shutdownInput();
        socket.shutdownOutput();
      } catch (IOException e) {
        e.printStackTrace();
      }
      System.out.println("服务器启动。。。");
    }catch (Exception e){
      e.printStackTrace();
    }

  }
}
